#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int head[N];
int ver[N << 1], W[N << 1], Next[N << 1], tot;
void add(int u, int v, int w) {
  ++tot;
  ver[tot] = v;
  W[tot] = w;
  Next[tot] = head[u];
  head[u] = tot;
}
int d[N];
void dfs(int u, int fu, int val) {
  d[u] = val;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    int w = W[i];
    dfs(v, u, d[u] ^ w);
  }
}
int tr[N << 5][2], num;
void insert(int x) {
  int p = 0;
  per(i, 30, 0) {
    int v = x & (1 << i);
    int ch = v ? 1 : 0;
    if (!tr[p][ch]) tr[p][ch] = ++num;
    p = tr[p][ch];
  }
}
int query(int x) {
  int p = 0, ans = 0;
  per(i, 30, 0) {
    int v = x & (1 << i);
    int ch = v ? 0 : 1;
    if (tr[p][ch])
      ans |= 1 << i;
    else
      ch ^= 1;
    p = tr[p][ch];
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 2, n) {
    int u, v, w;
    cin >> u >> v >> w;
    u++, v++;
    add(u, v, w), add(v, u, w);
  }
  dfs(1, 1, 0);
  int ans = 0;
  rep(i, 1, n) {
    insert(d[i]);
    ans = max({ans, d[i], query(d[i])});
  }
  cout << ans;
  return 0;
}